package com.example.mq;

/**
 * @BelongsProject: 0.mq
 * @BelongsPackage: com.example.mq
 * @Author : 游在海里的鱼
 * @CreateTime : 2023-12-21  21:29
 * @Version : 1.0
 * @Description : TODO
 */
import java.util.*;

class Node{
    int key;
    int val;
    Node pre;
    Node next;

    public Node(int key,int val){
        this.key = key;
        this.val = val;
    }
}

public class Solution {
    private Map<Integer,Node> map = new HashMap<>();
    private Node head = new Node(0,0);
    private Node end = new Node(0,0);

    private int size = 0;
    private int capacity;

    public Solution(int capacity) {
        this.capacity = capacity;
        head.next = end;
        end.pre = head;
    }

    public int get(int key) {
        // write code here
        return 0;
    }

    public void set(int key, int value) {
        if(size >= capacity){
            Node cur = head.next;
            cur.next.pre = head;
            head.next = cur.next;
            map.remove(cur.key);
        }
        System.out.println("---");
        Node fresh = new Node(key,value);
        map.put(key,fresh);
        function(fresh);
        size++;
        // write code here
    }
    private void function(Node cur){
        cur.pre.next = cur.next;
        cur.next.pre = cur.pre;
        cur.pre = end.pre;
        cur.next = end;
        end.pre = cur;
    }
}
